package com.lsa.edmonds.chap1;

import junit.framework.TestCase;
import com.lsa.helpers.Utils;
import com.lsa.shenn.common.InsertionSort;
import com.lsa.shenn.common.Sorter;
import com.lsa.shenn.common.SorterTestCaseBase;

public class TestChap1 extends SorterTestCaseBase
{
	public void testBinarySearch()
	{
		BinarySearch bs = new BinarySearch();
		int[] array = {1,1,2,4,5,7,8,8,9,9};
		// 0 1 2 3 4 5 6 7 8 9
		// 1 1 2 4 5 7 8 8 9 9
		
		assertEquals(-1, bs.search(array, 0));
		
		int idx = bs.search(array, 1);
		assertEquals(true, idx > -1 && idx < 2);
		
		idx = bs.search(array, 2);
		assertEquals(2, idx);
		
		idx = bs.search(array, 4);
		assertEquals(3, idx);

		idx = bs.search(array, 9);
		assertEquals(true, idx > 7 && idx < 10);
		
		array = new int[]{3,4};
		
		assertEquals(0, bs.search(array, 3));
		assertEquals(1, bs.search(array, 4));
		
		array = new int[]{3};
		assertEquals(0, bs.search(array, 3));
		
		array = new int[]{};
		assertEquals(-1, bs.search(array, 3));
		
		array = new int[]{3,4,5};
		assertEquals(0, bs.search(array, 3));
	}
	
	public void testTwoFingerMax()
	{
		TwoFingerMax tfm = new TwoFingerMax();
		
		int[] array = {8, 9, 1, 12, 1, 2, 5, 8, 9, 4};
		assertEquals(3, tfm.findFirstIndexOfMax(array));
	}
	
	public void testSelectionSort()
	{
		SelectionSort sorter = new SelectionSort();
		testSorter(sorter);
	}
	
	public void testInsertionSort()
	{
		InsertionSort sorter = new InsertionSort();
		testSorter(sorter);
	}
	
	public void testBubbleSort()
	{
		BubbleSort sorter = new BubbleSort();
		testSorter(sorter);
	}
}
